<template>
	<view>
		<view class="bg-white p-30 border-radius">
			<view class="form-item mb-40">
				<view class="font-bold font-28">姓名</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.username" placeholder="请输入姓名" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">手机号</view>
				<view class="mt-20">
					<uni-easyinput type="number" v-model="form.mobile" placeholder="请输入手机号" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">职务</view>
				<view class="mt-20">
					<uni-easyinput type="number" v-model="form.job" placeholder="请输入职务" />
				</view>
			</view>
		</view>
		<view class="bottom-view flex flex-colum flex-center">
			<view class="bottom-btn font-white bg-g" @click="submit">保存</view>
		</view>
	</view>
</template>

<script>
import { getInfo, edit, add } from '../../api/hr_user';
	
	export default {
		data() {
			return {
				form: {
					companyId: ''
				},
				isEdit: true
			};
		},
		onShow() {
			this.getHr()
			let companyId = uni.getStorageSync('companyId')
			if (companyId) {
				this.form.companyId = companyId
			}
		},
		methods: {
			getHr() {
				const _this = this
				getInfo().then(res => {
					if (res.code === 200) {
						this.form = res.result
					} else {
						if (this.form.companyId === '') {
							let companyId = uni.getStorageSync('companyId')
							if (!companyId) {
								this.$tips.showConfirmModal('请先添加公司信息', () => {
									uni.navigateTo({
										url: '/pages/company/form'
									})
								})
							}
						}
					}
				})
			},
			submit() {
				const _this = this
				this.$tips.showModal('是否提交职位信息？', () => {
					if (this.isEdit) {
						edit({
							...this.form
						}).then(res => {
							if (res.code === 200) {
								_this.$tips.showConfirmModal('提交成功，请等待审核', () => {
									uni.navigateBack()
								})
							} else {
								_this.$tips.showConfirmModal('提交失败，请重试', () => {})
							}
						})
					} else {
						add({
							...this.form
						}).then(res => {
							if (res.code === 200) {
								_this.$tips.showConfirmModal('提交成功，请等待审核', () => {
									uni.navigateBack()
								})
							} else {
								_this.$tips.showConfirmModal('提交失败，请重试', () => {})
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
		padding-bottom: 200rpx;
	}
	
	.bottom-view {
		width: 100vw;
		padding: 40rpx 0;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 99999;
		border-top: 1px solid #efefef;
	
		.bottom-btn {
			width: 80vw;
			text-align: center;
			border-radius: 50rpx;
			padding: 20rpx 0;
		}
	}
</style>